Class sjl.Vector
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class sjl.Vector

java.lang.Object
   |
   +----sjl.Vector

public class Vector
extends Object
implements ReversibleContainer, BackInsertContainer
Vector is a kind of sequence that supports random access iterators. In additition it supports (amortized) constant time insert and erase operations at the end; insert and erase in the middle take linear time. Storage management is handled automatically.

insert causes reallocation if the new size is greater than the old capacity. The iterators before the insertion point always remain valid. Inserting a single element into a vector is linear in the distance from the insertion point to the end of the vector. The amortized complexity over the lifetime of a vector of inserting a single element at the end is constant. Insertion of multiple elements into a vector with a single call of the insert method is linear in the sum of the number of elements plus the distance to the end of the vector.
In other words, it is mush faster to insert many elements into the middle of a vector at once, than to do the insertion one at a time.

erase invalidates all the iterators after the point of the erase.

Copyright © 1996 Finn Bock


Variable Index

 o data
Private.

Constructor Index

 o Vector()
Construct a new empty Vector.
 o Vector(ForwardIterator, ForwardIterator)
Construct a new Vector with the contents of the range [first,last).
 o Vector(int, Object)
Construct a new Vector with an initial size of size elements, each element initialized to with a reference to value.
 o Vector(Vector)
Construct a new Vector with the size and contents of another vector.

Method Index

 o back()
Return the last element in the container.
 o begin()
Returns the iterator that represents the beginning of the vector.
 o beginGeneric()
Returns the iterator that represents the beginning of the vector as an untyped iterator.
 o beginRef()
Returns a reference to the iterator that represents the beginning of the vector.
 o capacity()
Returns the maximum number of elements that can be stored in the vector without reallocation.
 o empty()
Returns true if the vector does not contain any elements.
 o end()
Returns the iterator that represents the end of the vector.
 o endGeneric()
Returns the iterator that represents the end of the vector as an untyped iterator.
 o endRef()
Returns a reference to the iterator that represents the end of the vector.
 o equals(Object)
Compare the elements in this container with the elements in another container.
 o erase(Iterator)
Removes the element specified by position.
 o erase(Iterator, Iterator)
Removes the elements in the specified range.
 o flush()
Erase all the elements in the container.
 o front()
Return the first element in the container.
 o get(int)
Returns the nth element in the container.
 o insert(Iterator, InputIterator, InputIterator)
The elements in the range [first,last) are inserted into vector at the specified position.
 o insert(Iterator, int, Object)
Insert n references to element into the vector at the specified position.
 o insert(Iterator, Object)
Insert an element into the vector at the specified position.
 o max_size()
Returns the maximum number of elements that can be stored in a vector.
 o pop_back()
Removes the last element in vector.
 o push_back(Object)
Add an element to the end of the vector.
 o put(int, Object)
Set the nth element in the container to o.
 o rbegin()
Returns a copy of the reverse iterator that represents the beginning (end) of the list.
 o rbeginGeneric()
Returns a copy of the reverse iterator that represents the beginning (end) of the list as an untyped Iterator.
 o rend()
Returns a copy of the iterator that represents the end (beginning) of the list.
 o rendGeneric()
Returns a copy of the iterator that represents the end (beginning) of the list as an untyped Iterator.
 o size()
Returns the number of elements stored in the vector.
 o toString()
Returns the string representation of this vector.

Variables

 o data
  protected Object data[]
Private. The actual data array.

Constructors

 o Vector
  public Vector()
Construct a new empty Vector.
 o Vector
  public Vector(int size,
                Object value)
Construct a new Vector with an initial size of size elements, each element initialized to with a reference to value.
Parameters:
size - The size of the new vector.
value - The initial value of each element in the vector.
 o Vector
  public Vector(Vector vector)
Construct a new Vector with the size and contents of another vector.
Parameters:
vector - The vector which is copied into the new vector.
 o Vector
  public Vector(ForwardIterator first,
                ForwardIterator last)
Construct a new Vector with the contents of the range [first,last).
Parameters:
first - The beginning of the range.
last - The end of the range.

Methods

 o flush
  public void flush()
Erase all the elements in the container.
 o equals
  public boolean equals(Object container)
Compare the elements in this container with the elements in another container.
Returns:
true is the elements match.
Overrides:
equals in class Object
 o begin
  public VectorIterator begin()
Returns the iterator that represents the beginning of the vector.
 o beginRef
  public VectorIterator beginRef()
Returns a reference to the iterator that represents the beginning of the vector.
 o end
  public VectorIterator end()
Returns the iterator that represents the end of the vector.
 o endRef
  public VectorIterator endRef()
Returns a reference to the iterator that represents the end of the vector.
 o beginGeneric
  public ForwardIterator beginGeneric()
Returns the iterator that represents the beginning of the vector as an untyped iterator.
 o endGeneric
  public ForwardIterator endGeneric()
Returns the iterator that represents the end of the vector as an untyped iterator.
 o rbegin
  public ReverseRandomIterator rbegin()
Returns a copy of the reverse iterator that represents the beginning (end) of the list.
 o rend
  public ReverseRandomIterator rend()
Returns a copy of the iterator that represents the end (beginning) of the list.
 o rbeginGeneric
  public Iterator rbeginGeneric()
Returns a copy of the reverse iterator that represents the beginning (end) of the list as an untyped Iterator.
 o rendGeneric
  public Iterator rendGeneric()
Returns a copy of the iterator that represents the end (beginning) of the list as an untyped Iterator.
 o size
  public int size()
Returns the number of elements stored in the vector.
 o max_size
  public int max_size()
Returns the maximum number of elements that can be stored in a vector.
 o capacity
  public int capacity()
Returns the maximum number of elements that can be stored in the vector without reallocation.
 o empty
  public boolean empty()
Returns true if the vector does not contain any elements.
 o get
  public Object get(int n)
Returns the nth element in the container.
 o put
  public Object put(int n,
                    Object o)
Set the nth element in the container to o.
 o front
  public Object front()
Return the first element in the container.
 o back
  public Object back()
Return the last element in the container.
 o push_back
  public void push_back(Object o)
Add an element to the end of the vector.
 o insert
  public Iterator insert(Iterator position,
                         Object o)
Insert an element into the vector at the specified position. Elements located after the position are moved.
Parameters:
position - insert the element at this position.
o - the element to insert.
Returns:
An iterator to the position where the element was inserted.
 o insert
  public void insert(Iterator position,
                     int n,
                     Object o)
Insert n references to element into the vector at the specified position. Elements located after the position are moved.
Parameters:
position - insert the element at this position.
n - the number of elements to insert.
o - the element to insert.
 o insert
  public void insert(Iterator position,
                     InputIterator first,
                     InputIterator last)
The elements in the range [first,last) are inserted into vector at the specified position. Elements located after the position are moved.
Parameters:
position - insert the element at this position.
first - the beginning of the range.
last - the end of the range.
 o pop_back
  public void pop_back()
Removes the last element in vector.
 o erase
  public void erase(Iterator position)
Removes the element specified by position.
 o erase
  public void erase(Iterator first,
                    Iterator last)
Removes the elements in the specified range.
Parameters:
first - the beginning of the range.
last - the end of the range.
 o toString
  public String toString()
Returns the string representation of this vector.
Overrides:
toString in class Object

All Packages  Class Hierarchy  This Package  Previous  Next  Index